angular.module('img-picker', [])

.directive 'imgPicker', ->
    restrict    : 'E'
    templateUrl : 'templates/img-picker/img-picker.html'
    scope:
        'items' : '=items'
        'disabled' : '=isupk'
    link: ($scope, $element, $attrs) ->

.controller 'imgPickerCtrl', ($scope, $state, $ionicHistory,showToast,$ionicViewSwitcher,userData,$cordovaCamera,$ionicPopup) ->
    _.extend $scope,
        imgAdd: ->
            if $scope.disabled.isupk == '1'
                showToast '优品库的商品不能上传新图片'
                return false
            else
                options =
                    quality: 50
                    destinationType: Camera.DestinationType.DATA_URL
                    sourceType: Camera.PictureSourceType.PHOTOLIBRARY
                    allowEdit: true
                    encodingType: Camera.EncodingType.JPEG
                    popoverOptions: CameraPopoverOptions
                    saveToPhotoAlbum: false
                $cordovaCamera.getPicture(options).then ((imageData) ->
                    $scope.items.push {img:"data:image/jpeg;base64," + imageData}
                ), (err) -> null
        remove: (i)->
            $scope.items.splice(i,1)







